import { request as http } from '../service'
import IBaseObj from '#/index'

const base = '/org'

const getOrgByPage = (data: IBaseObj) =>
  http({
    url: `${base}/query`,
    method: 'post',
    data,
  })

const saveOrg = (data: IBaseObj) =>
  http({
    url: `${base}/create`,
    method: 'post',
    data,
  })

const updateOrg = (data: IBaseObj) =>
  http({
    url: `${base}/modify`,
    method: 'post',
    data,
  })

const getOrgById = (id: string | number) =>
  http({
    url: `${base}/${id}`,
    method: 'get',
  })

const delUrl = base

// type = 0 标识查全部机构
export const getOrgList = (
  params: { enable: number; type: string | number } = { enable: 1, type: 0 }
) =>
  http({
    url: `${base}/list`,
    method: 'get',
    params: params,
  })

const getOrgByTypes = (types: number[]) =>
  http({
    url: `${base}/list/types`,
    method: 'post',
    data: types,
  })

// 获取组织list,排除已加入的组织
const getOrgStationList = (pid: string) =>
  http({
    url: `${base}/list/station`,
    method: 'get',
    params: {
      pid,
    },
  })

export default {
  getOrgList,
  getOrgByPage,
  saveOrg,
  updateOrg,
  getOrgById,
  getOrgByTypes,
  getOrgStationList,
  delUrl,
}
